package com.beasu.tingting

import android.content.SharedPreferences
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI
import androidx.preference.PreferenceManager
import com.beasu.tingting.ui.main.MainFragment
import com.beasu.tingting.ui.main.MainViewModel

class MainActivity : AppCompatActivity() {
    lateinit var  viewModel  : MainViewModel
    lateinit var manager :SharedPreferences
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.main_activity)
        val controller :NavController = Navigation.findNavController(this,R.id.fragment)
        NavigationUI.setupActionBarWithNavController(this,controller)
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        return super.onCreateOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
       when( item?.itemId){
           R.id.menu_setting ->{
               val controller :NavController = Navigation.findNavController(this,R.id.fragment)
               controller.navigate(R.id.action_mainFragment_to_settingFragment)
           }
       }
        return super.onOptionsItemSelected(item)
    }

    override fun onSupportNavigateUp(): Boolean {
        val controller  = Navigation.findNavController(this,R.id.fragment)
        return controller.navigateUp()

    }

}
